package com.huika.renrench.control.my.adapter;

import android.content.Context;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.huika.lib.utils.MoneyShowTool;
import com.huika.renrench.R;
import com.huika.renrench.control.common.base.BaseAda;
import com.huika.renrench.control.my.utils.TransactionUtils;
import com.huika.renrench.support.bean.TransactionRecordBean;
import com.huika.renrench.utils.DateTimeTool;

public class TransactionRecordAdapter extends BaseAda<TransactionRecordBean> {

	SparseArray<View> map = new SparseArray<View>();
	
	public TransactionRecordAdapter(Context context) {
		super(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if(map.get(position) == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.item_transaction_record, null);
			holder.time = (TextView) convertView.findViewById(R.id.time);
			holder.remark = (TextView) convertView.findViewById(R.id.remark);
			holder.money = (TextView) convertView.findViewById(R.id.money);
			holder.detail = (TextView) convertView.findViewById(R.id.detail);
			convertView.setTag(holder);
			final int p = position;
			map.put(p, convertView);
		} else {
			convertView = map.get(position);
			holder = (ViewHolder) convertView.getTag();
		}
		TransactionRecordBean bean = group.get(position);
		holder.time.setText(DateTimeTool.ymdhmsDate(bean.getCreateDt()));
		
		holder.remark.setText(TransactionUtils.getMsg(bean.getCapitalType()));
		holder.detail.setText(TransactionUtils.getTradeResultMsg(bean.getCapitalType(), bean.status));
		if(bean.getIsAddOrCut() == 1) {
			holder.money.setText("+" + MoneyShowTool.twolastDF(Double.parseDouble(bean.getAmount()))  + "元");
		} else if(bean.getIsAddOrCut() == 2) {
			
			holder.money.setText("-" + MoneyShowTool.twolastDF(Double.parseDouble(bean.getAmount()))  + "元");
		}
		return convertView;
	}
	
	private static class ViewHolder {
		TextView time;
		TextView remark;
		TextView money;
		TextView detail;
	}

}
